package com.hj.controller;

import java.util.Date;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.hj.pojo.Student;
import com.hj.pojo.Teacher;
import com.hj.service.IStudentService;
import com.hj.service.ITeacherService;
import com.hj.vo.PageResult;
import com.hj.vo.Result;

@RestController
@CrossOrigin
public class LoginController {

    @Autowired
    IStudentService studentService;
    @Autowired
    HttpSession session;

    @GetMapping("/test")
    public Object list() throws Exception {
    	
//    	String info = "{name:xiaoming, age:12, score:56, birth:2020-02-02}";
    	
    	Thread.sleep(5000);
    	
    	Student stu = new Student();
    	stu.setsBirth(new Date());
    	stu.setsName("xiaoming");
    	stu.setsSex("男");
    	return stu;
    }
    
    @PostMapping("/login")
    public Result login(String uname, String passwd) {
    	
    	Student stu = studentService.login(uname, passwd);
    	
    	session.setAttribute("sessionUid", stu.getsId());
    	
    	Result result = new Result();
        result.setCode(200);
        result.setMsg("ok");
    	
        return result;
    }

}
